﻿using System;
using System.Runtime.InteropServices;

namespace Nivot.PowerShell.WindowsMobile.Rapi2
{

    #region Structs

    [StructLayout(LayoutKind.Sequential)]
    internal class CFILETIME
    {
        public CFILETIME(DateTime dt)
        {
            long hFT1 = dt.ToFileTimeUtc();
            this.dwLowDateTime = (int) (hFT1 & 0xFFFFFFFF);
            this.dwHighDateTime = (int) (hFT1 >> 32);
        }

        public int dwHighDateTime;
        public int dwLowDateTime;
    }

    [StructLayout(LayoutKind.Sequential, Pack = 4)]
    internal struct PROCESS_INFORMATION
    {
        public IntPtr hProcess;
        public IntPtr hThread;
        public int dwProcessID;
        public int dwThreadID;
    }

    [StructLayout(LayoutKind.Sequential, Size = 16)]
    internal struct CEPROPVAL
    {
        private int propid;
        private ushort wLenData;
        private ushort wFlags;
        private long val;
    }

    [StructLayout(LayoutKind.Sequential)]
    internal struct SORTORDERSPEC
    {
        public SORTORDERSPEC(int pid, int flgs)
        {
            propid = pid;
            dwFlags = flgs;
        }

        private int propid;
        private int dwFlags;
    }

    [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
    internal struct CE_FIND_DATA
    {
        [FieldOffset(0)] public uint dwFileAttributes;
        [FieldOffset(4)] public System.Runtime.InteropServices.ComTypes.FILETIME ftCreationTime;
        [FieldOffset(12)] public System.Runtime.InteropServices.ComTypes.FILETIME ftLastAccessTime;
        [FieldOffset(20)] public System.Runtime.InteropServices.ComTypes.FILETIME ftLastWriteTime;
        [FieldOffset(28)] public uint nFileSizeHigh;
        [FieldOffset(32)] public uint nFileSizeLow;
        [FieldOffset(36)] public uint dwOID;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260), FieldOffset(40)] public string Name;
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Size = 88)]
    internal struct CEDBASEINFO
    {
        public uint dwFlags;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string szDbaseName;
        public uint dwDbaseType;
        public ushort wNumRecords;
        public ushort wNumSortOrder;
        public uint dwSize;
        public System.Runtime.InteropServices.ComTypes.FILETIME ftLastModified;
        //[MarshalAs(UnmanagedType.LPArray, ArraySubType = typeof(SORTORDERSPEC), SizeConst = 4)]
        //public SORTORDERSPEC[] rgSortSpecs;
    }

    [StructLayout(LayoutKind.Sequential)]
    internal struct CEDB_FIND_DATA
    {
        public uint OidDb;
        public CEDBASEINFO DbInfo;
    }


    /// <summary>
    /// Version info for the connected device
    /// </summary>
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    internal struct CEOSVERSIONINFO
    {
        internal int dwOSVersionInfoSize;

        /// <summary>
        /// Major
        /// </summary>
        public int dwMajorVersion;

        /// <summary>
        /// Minor
        /// </summary>
        public int dwMinorVersion;

        /// <summary>
        /// Build
        /// </summary>
        public int dwBuildNumber;

        /// <summary>
        /// Platform type
        /// </summary>
        public int dwPlatformId;

        /// <summary>
        /// Null-terminated string that provides arbitrary additional information about the operating system.
        /// </summary>
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string szCSDVersion;
    }

    internal enum RAPI_GETDEVICEOPCODE
    {
        RAPI_GETDEVICE_NONBLOCKING,
        RAPI_GETDEVICE_BLOCKING
    }

    [StructLayout(LayoutKind.Explicit, Size = 128)]
    internal struct SOCKADDR_STORAGE
    {
        [FieldOffset(0)] public short ss_family; // Address family.
        [FieldOffset(2)] public ushort port;
        [FieldOffset(4)] public int addr;
    }

    [StructLayout(LayoutKind.Sequential)]
    internal struct RAPI_CONNECTIONINFO
    {
        public SOCKADDR_STORAGE ipaddr;
        public SOCKADDR_STORAGE hostIpaddr;
        public ConnectionType connectionType;
    }

    [StructLayout(LayoutKind.Sequential)]
    internal struct RAPI_DEVICEINFO
    {
        public Guid DeviceId;
        public int dwOsVersionMajor;
        public int dwOsVersionMinor;
        [MarshalAs(UnmanagedType.BStr)] public string bstrName;
        [MarshalAs(UnmanagedType.BStr)] public string bstrPlatform;
    }

    internal static class HKEY
    {
        public static readonly uint HKEY_CLASSES_ROOT = 0x80000000;
        public static readonly uint HKEY_CURRENT_USER = 0x80000001;
        public static readonly uint HKEY_LOCAL_MACHINE = 0x80000002;
        public static readonly uint HKEY_USERS = 0x80000003;
    }

    #endregion

    [ComImport, Guid("35440327-1517-4B72-865E-3FFE8E97002F")]
    internal class RAPI2
    {
    }

    [Guid("76a78b7d-8e54-4c06-ac38-459e6a1ab5e3"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface IRAPISession
    {
        void CeRapiInit();

        void CeRapiUninit();

        [PreserveSig]
        int CeGetLastError();

        int CeRapiGetError();

        void CeRapiFreeBuffer(
            [In] IntPtr Buffer);

        [PreserveSig]
        IntPtr CeFindFirstFile(
            [In, MarshalAs(UnmanagedType.LPWStr)] string FileName,
            [In, Out, MarshalAs(UnmanagedType.Struct)] ref CE_FIND_DATA FindData);

        [PreserveSig]
        int CeFindNextFile(
            [In] IntPtr FoundFile,
            [In, Out, MarshalAs(UnmanagedType.Struct)] ref CE_FIND_DATA FindData);

        [PreserveSig]
        int CeFindClose(
            [In] IntPtr FoundFile);

        [PreserveSig]
        uint CeGetFileAttributes(
            [In, MarshalAs(UnmanagedType.LPWStr)] string FileName);

        [PreserveSig]
        int CeSetFileAttributes(
            [In, MarshalAs(UnmanagedType.LPWStr)] string FileName,
            [In] uint FileAttrib);

        [PreserveSig]
        IntPtr CeCreateFile(
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpFileName,
            [In] uint dwDesiredAccess,
            [In] uint dwShareMode,
            [In] IntPtr lpSecurityAttributes,
            [In] uint dwCreationDistribution,
            [In] uint dwFlagsAndAttributes,
            [In] IntPtr hTemplateFile);

        [PreserveSig]
        int CeReadFile(
            [In] IntPtr hFile,
            [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] byte[] lpBuffer,
            [In] uint nNumberOfBytesToRead,
            [In, Out] ref int lpNumberOfBytesRead,
            [In] IntPtr lpOverlapped);

        [PreserveSig]
        int CeWriteFile(
            [In] IntPtr hFile,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] byte[] lpBuffer,
            [In] int nNumberOfBytesToWrite,
            [In, Out] ref int lpNumberOfBytesWritten,
            [In] IntPtr lpOverlapped);

        [PreserveSig]
        int CeCloseHandle(
            [In] IntPtr hObject);

        [PreserveSig]
        int CeFindAllFiles(
            [In, MarshalAs(UnmanagedType.LPWStr)] string Path,
            [In] int Flags,
            [In, Out] ref int pFoundCount,
            [Out] out IntPtr ppFindDataArray);

        [PreserveSig]
        IntPtr CeFindFirstDatabase(
            [In] uint dwDbaseType);

        [PreserveSig]
        int CeFindNextDatabase(
            [In] IntPtr hEnum);

        IntPtr /*CEOIDINFO*/ CeOidGetInfo([In] int oid);

        [PreserveSig]
        int CeCreateDatabase(
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszName,
            [In] uint dwDbaseType,
            [In] ushort cNumSortOrder,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] SORTORDERSPEC[] rgSortSpecs);

        [PreserveSig]
        IntPtr CeOpenDatabase(
            [In, Out] IntPtr poid,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszName,
            [In] int propid,
            [In] uint dwFlags,
            [In] IntPtr hwndNotify);

        [PreserveSig]
        int CeDeleteDatabase(
            [In] int oidDbase);

        [PreserveSig]
        int CeReadRecordProps(
            [In] IntPtr hDbase,
            [In] uint dwFlags,
            [In, Out] ref ushort lpcPropID,
            [In, Out] ref int rgPropID,
            [In, Out] IntPtr lplpBuffer,
            [In, Out] ref int lpcbBuffer);

        [PreserveSig]
        int CeWriteRecordProps(
            [In] IntPtr hDbase,
            [In] int oidRecord,
            [In] ushort cPropID,
            ref CEPROPVAL rgPropVal);

        [PreserveSig]
        int CeDeleteRecord(
            [In] IntPtr hDatabase,
            [In] int oidRecord);

        [PreserveSig]
        int CeSeekDatabase(
            [In] IntPtr hDatabase,
            [In] uint dwSeekType,
            [In] uint dwValue,
            [In, Out] ref int lpdwIndex);

        [PreserveSig]
        int CeSetDatabaseInfo(
            [In] int oidDbase,
            ref IntPtr /*CEDBASEINFO*/ pNewInfo);

        [PreserveSig]
        int CeSetFilePointer(
            [In] IntPtr hFile,
            [In] int lDistanceToMove,
            [In, Out] ref int lpDistanceToMoveHigh,
            [In] uint dwMoveMethod);

        [PreserveSig]
        int CeSetEndOfFile(
            [In] IntPtr hFile);

        [PreserveSig]
        int CeCreateDirectory(
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpPathName,
            [In] IntPtr lpSecurityAttributes);

        [PreserveSig]
        int CeRemoveDirectory(
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpPathName);

        [PreserveSig]
        int CeCreateProcess(
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszImageName,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszCmdLine,
            [In] int lpsaProcess,
            [In] int lpsaThread,
            [In] int fInheritHandles,
            [In] int fdwCreate,
            [In] int lpvEnvironment,
            [In] int lpszCurDir,
            [In] int lpsiStartInfo,
            [Out] out PROCESS_INFORMATION lppiProcInfo);

        [PreserveSig]
        int CeMoveFile(
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpExistingFileName,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpNewFileName);

        [PreserveSig]
        int CeCopyFile(
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpExistingFileName,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpNewFileName,
            [In] int bFailIfExists);

        [PreserveSig]
        int CeDeleteFile(
            [In, MarshalAs(UnmanagedType.LPWStr)] string FileName);

        [PreserveSig]
        uint CeGetFileSize(
            [In] IntPtr hFile,
            [In, Out] ref uint lpFileSizeHigh);

        [PreserveSig]
        int CeRegOpenKeyEx(
            [In] uint hKey,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszSubKey,
            [In] uint dwReserved,
            [In] uint samDesired,
            [In, Out] ref uint phkResult);

        [PreserveSig]
        int CeRegEnumKeyEx(
            [In] uint hKey,
            [In] uint dwIndex,
            [In, Out] System.Text.StringBuilder lpName,
            [In, Out] ref uint lpcbName,
            [In] int lpReserved,
            [In, Out] System.Text.StringBuilder lpClass,
            [In, Out] ref uint lpcbClass,
            [In] IntPtr lpftLastWriteTime);

        [PreserveSig]
        int CeRegCreateKeyEx(
            [In] uint hKey,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszSubKey,
            [In] int dwReserved,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszClass,
            [In] uint fdwOptions,
            [In] uint samDesired,
            [In] IntPtr lpSecurityAttributes,
            [In, Out] ref uint phkResult,
            [In, Out] ref uint lpdwDisposition);

        [PreserveSig]
        int CeRegCloseKey(
            [In] uint hKey);

        [PreserveSig]
        int CeRegDeleteKey(
            [In] uint hKey,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszSubKey);

        [PreserveSig]
        int CeRegEnumValue(
            [In] uint hKey,
            [In] uint dwIndex,
            [In, Out] System.Text.StringBuilder lpszValueName,
            [In, Out] ref uint lpcbValueName,
            [In, Out] int lpReserved,
            [Out] out uint lpType,
            [In, Out] IntPtr lpData,
            [In, Out] ref uint lpcbData);

        [PreserveSig]
        int CeRegDeleteValue(
            [In] uint hKey,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszValueName);

        [PreserveSig]
        int CeRegQueryInfoKey(
            [In] uint hKey,
            [Out, MarshalAs(UnmanagedType.LPWStr)] string lpClass,
            [In, Out] ref int lpcbClass,
            [In] IntPtr lpReserved,
            [Out] out int lpcSubKeys,
            [Out] out int lpcbMaxSubKeyLen,
            [Out] out int lpcbMaxClassLen,
            [Out] out int lpcValues,
            [Out] out int lpcbMaxValueNameLen,
            [Out] out int lpcbMaxValueLen,
            [In] IntPtr lpcbSecurityDescriptor,
            [In] IntPtr lpftLastWriteTime);

        [PreserveSig]
        int CeRegQueryValueEx(
            [In] uint hKey,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpValueName,
            [In] IntPtr lpReserved,
            [Out] out int lpType,
            [In, Out] IntPtr lpData,
            [In, Out] ref int lpcbData);

        [PreserveSig]
        int CeRegSetValueEx(
            [In] uint hKey,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpValueName,
            [In] int Reserved,
            [In] int dwType,
            [In] IntPtr lpData,
            [In] int cbData);

        [PreserveSig]
        int CeGetStoreInformation(
            ref StoreInfo lpsi);

        [PreserveSig]
        int CeGetSystemMetrics(
            [In] int nIndex);

        [PreserveSig]
        int CeGetDesktopDeviceCaps(
            [In] int nIndex);

        [PreserveSig]
        int CeFindAllDatabases(
            [In] int DbaseType,
            [In] ushort Flags,
            [In, Out] ref ushort cFindData,
            [Out] out IntPtr ppFindData);

        void CeGetSystemInfo(ref SystemInformation sysInfo);

        [PreserveSig]
        int CeSHCreateShortcut(
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszShortcut,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszTarget);

        [PreserveSig]
        int CeSHGetShortcutTarget(
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszShortcut,
            [In, Out] System.Text.StringBuilder lpszTarget,
            [In] int cbMax);

        [PreserveSig]
        int CeCheckPassword(
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszPassword);

        [PreserveSig]
        int CeGetFileTime(
            [In] IntPtr hFile,
            [In, Out] ref System.Runtime.InteropServices.ComTypes.FILETIME lpCreationTime,
            [In, Out] ref System.Runtime.InteropServices.ComTypes.FILETIME lpLastAccessTime,
            [In, Out] ref System.Runtime.InteropServices.ComTypes.FILETIME lpLastWriteTime);

        [PreserveSig]
        int CeSetFileTime(
            [In] IntPtr hFile,
            [In] CFILETIME lpCreationTime,
            [In] CFILETIME lpLastAccessTime,
            [In] CFILETIME lpLastWriteTime);

        [PreserveSig]
        int CeGetVersionEx(
            ref CEOSVERSIONINFO lpVersionInformation);

        [PreserveSig]
        IntPtr CeGetWindow(
            [In] IntPtr hWnd,
            [In] uint uCmd);

        [PreserveSig]
        int CeGetWindowLong(
            [In] IntPtr hWnd,
            [In] int nIndex);

        [PreserveSig]
        int CeGetWindowText(
            [In] IntPtr hWnd,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpString,
            [In] int nMaxCount);

        [PreserveSig]
        int CeGetClassName(
            [In] IntPtr hWnd,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpClassName,
            [In] int nMaxCount);

        void CeGlobalMemoryStatus(
            ref MemoryStatus lpmst);

        [PreserveSig]
        int CeGetSystemPowerStatusEx(
            ref PowerStatus pstatus,
            [In] int fUpdate);

        [PreserveSig]
        int CeGetTempPath(
            [In] int nBufferLength,
            [In, Out] System.Text.StringBuilder lpBuffer);

        [PreserveSig]
        int CeGetSpecialFolderPath(
            [In] int nFolder,
            [In] int nBufferLength,
            [In, Out] System.Text.StringBuilder lpBuffer);

        void CeRapiInvoke(
            [In, MarshalAs(UnmanagedType.LPWStr)] string pDllPath,
            [In, MarshalAs(UnmanagedType.LPWStr)] string pFunctionName,
            [In] int cbInput,
            [In] IntPtr pInput,
            [Out] out int pcbOutput,
            [Out] out IntPtr ppOutput,
            [In, Out, MarshalAs(UnmanagedType.IUnknown)] ref IntPtr ppIRAPIStream,
            [In] int dwReserved);

        [PreserveSig]
        IntPtr CeFindFirstDatabaseEx(
            ref Guid pguid,
            [In] int dwDbaseType);

        [PreserveSig]
        int CeFindNextDatabaseEx(
            [In] IntPtr hEnum,
            ref Guid pguid);

        [PreserveSig]
        int CeCreateDatabaseEx(
            ref Guid pceguid,
            ref IntPtr /*CEDBASEINFO*/ lpCEDBInfo);

        [PreserveSig]
        int CeSetDatabaseInfoEx(
            ref Guid pceguid,
            [In] int oidDbase,
            ref IntPtr /*CEDBASEINFO*/ pNewInfo);

        [PreserveSig]
        IntPtr CeOpenDatabaseEx(
            ref Guid pceguid,
            ref int poid,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszName,
            int propid,
            [In] int dwFlags,
            ref IntPtr /*CENOTIFYREQUEST*/ pReq);

        [PreserveSig]
        int CeDeleteDatabaseEx(
            ref Guid pceguid,
            [In] int oidDbase);

        [PreserveSig]
        int CeReadRecordPropsEx(
            [In] IntPtr hDbase,
            [In] int dwFlags,
            [In, Out] ref ushort lpcPropID,
            [In, Out] ref int rgPropID,
            [In, Out] ref IntPtr lplpBuffer,
            [In, Out] ref int lpcbBuffer,
            [In] IntPtr hHeap);

        [PreserveSig]
        int CeMountDBVol(
            ref Guid pceguid,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpszDBVol,
            [In] int dwFlags);

        [PreserveSig]
        int CeUnmountDBVol(
            ref Guid pceguid);

        [PreserveSig]
        int CeFlushDBVol(
            ref Guid pceguid);

        [PreserveSig]
        int CeEnumDBVolumes(
            ref Guid pceguid,
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpBuf,
            [In] int dwNumChars);

        [PreserveSig]
        int CeOidGetInfoEx(
            ref Guid pceguid,
            [In] int oid,
            ref IntPtr /*CEOIDINFO*/ oidInfo);

        void CeSyncStart(
            [In, MarshalAs(UnmanagedType.LPWStr)] string szCommand);

        void CeSyncStop();

        [PreserveSig]
        int CeQueryInstructionSet(
            [In] int dwInstructionSet,
            [In, Out] ref int lpdwCurrentInstructionSet);

        [PreserveSig]
        int CeGetDiskFreeSpaceEx(
            [In, MarshalAs(UnmanagedType.LPWStr)] string lpDirectoryName,
            ref ulong lpFreeBytesAvailableToCaller,
            ref ulong lpTotalNumberOfBytes,
            ref ulong lpTotalNumberOfFreeBytes);
    } ;

    [Guid("8a0f1632-3905-4ca4-aea4-7e094ecbb9a7"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface IRAPIDevice
    {
        DeviceStatus GetConnectStat();

        void GetDeviceInfo(
            ref RAPI_DEVICEINFO pDevInfo);

        void GetConnectionInfo(
            ref RAPI_CONNECTIONINFO pConnInfo);

        IRAPISession CreateSession();
    } ;

    [Guid("357a557c-b03f-4240-90d8-c6c71c659bf1"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface IRAPIEnumDevices
    {
        IRAPIDevice Next();

        void Reset();

        void Skip(uint cElt);

        IRAPIEnumDevices Clone();

        int GetCount();
    }

    [Guid("b4fd053e-4810-46db-889b-20e638e334f0"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface IRAPISink
    {
        [PreserveSig]
        void OnDeviceConnected(
            [In, MarshalAs(UnmanagedType.Interface)] IRAPIDevice pIDevice);

        [PreserveSig]
        void OnDeviceDisconnected(
            [In, MarshalAs(UnmanagedType.Interface)] IRAPIDevice pIDevice);
    } ;

    internal class RAPISink : IRAPISink
    {
        #region IRAPISink Members

        /// <summary>Raises the <see cref="E:RAPISink.DeviceConnected"/> event.</summary>
        public void OnDeviceConnected(IRAPIDevice pIDevice)
        {
            EventHandler temp = DeviceConnected;
            if (temp != null)
            {
                temp(this, new EventArgs());
            }
        }

        /// <summary>Raises the <see cref="E:RAPISink.DeviceDisconnected"/> event.</summary>
        public void OnDeviceDisconnected(IRAPIDevice pIDevice)
        {
            EventHandler temp = DeviceDisconnected;
            if (temp != null)
            {
                temp(this, new EventArgs());
            }
        }

        #endregion

        /// <summary>Occurs when device connected.</summary>
        public event EventHandler DeviceConnected;

        /// <summary>Occurs when device disconnected.</summary>
        public event EventHandler DeviceDisconnected;
    }

    [Guid("dcbeb807-14d0-4cbd-926c-b991f4fd1b91"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    internal interface IRAPIDesktop
    {
        void FindDevice(
            ref Guid pDeviceID,
            RAPI_GETDEVICEOPCODE opFlags,
            [Out, MarshalAs(UnmanagedType.Interface)] out IRAPIDevice ppIDevice);

        IRAPIEnumDevices EnumDevices();

        void Advise(
            [In, MarshalAs(UnmanagedType.Interface)] IRAPISink pISink,
            out int pdwContext);

        void UnAdvise(
            int dwContext);
    } ;

    [Serializable, Flags]
    public enum CeFindAllFilesFlags
    {
        FAF_ATTRIBUTES = 0x01,
        FAF_CREATION_TIME = 0x02,
        FAF_LASTACCESS_TIME = 0x04,
        FAF_LASTWRITE_TIME = 0x08,
        FAF_SIZE_HIGH = 0x10,
        FAF_SIZE_LOW = 0x20,
        FAF_OID = 0x40,
        FAF_NAME = 0x80,
        FAF_FLAG_COUNT = 8,
        FAF_ATTRIB_CHILDREN = 0x01000,
        FAF_ATTRIB_NO_HIDDEN = 0x02000,
        FAF_FOLDERS_ONLY = 0x04000,
        FAF_NO_HIDDEN_SYS_ROMMODULES = 0x08000,
        FAF_GETTARGET = 0x10000
    }

    internal static class Constants
    {
        //
        // These are flags for CeFindAllFiles
        //
        internal const uint FAD_FLAG_COUNT = 9;
        internal const uint FAD_FLAGS = 0x02;
        internal const uint FAD_LAST_MODIFIED = 0x80;
        internal const uint FAD_NAME = 0x04;
        internal const uint FAD_NUM_RECORDS = 0x10;
        internal const uint FAD_NUM_SORT_ORDER = 0x20;
        internal const uint FAD_OID = 0x01;
        internal const uint FAD_SIZE = 0x40;
        internal const uint FAD_SORT_SPECS = 0x100;
        internal const uint FAD_TYPE = 0x08;
        internal const uint FAF_ATTRIB_CHILDREN = 0x01000;
        internal const uint FAF_ATTRIB_NO_HIDDEN = 0x02000;
        internal const uint FAF_ATTRIBUTES = 0x01;
        internal const uint FAF_CREATION_TIME = 0x02;
        internal const uint FAF_FLAG_COUNT = 8;
        internal const uint FAF_FOLDERS_ONLY = 0x04000;
        internal const uint FAF_GETTARGET = 0x10000;
        internal const uint FAF_LASTACCESS_TIME = 0x04;
        internal const uint FAF_LASTWRITE_TIME = 0x08;
        internal const uint FAF_NAME = 0x80;
        internal const uint FAF_NO_HIDDEN_SYS_ROMMODULES = 0x08000;
        internal const uint FAF_OID = 0x40;
        internal const uint FAF_SIZE_HIGH = 0x10;
        internal const uint FAF_SIZE_LOW = 0x20;
        internal const uint FILE_ATTRIBUTE_HAS_CHILDREN = 0x00010000;

        internal const uint FILE_ATTRIBUTE_INROM = 0x00000040;
        internal const uint FILE_ATTRIBUTE_ROMMODULE = 0x00002000;
        internal const uint FILE_ATTRIBUTE_ROMSTATICREF = 0x00001000;

        //
        // The following is not a standard Windows CE File Attribute.
        //

        internal const uint FILE_ATTRIBUTE_SHORTCUT = 0x00020000;
    }
}